package com.jdk.demo.nio.bytebuffer;

import java.nio.ByteBuffer;

public class TestByteBuffer3 {

	private static ByteBuffer byteBuffer = null;

	public static void main(String[] args) {
		/* 以下顺序不要改变 */
		initByteBuffer();
		byteBuffer.put((byte)1);
		byteBuffer.putChar('a');
		byteBuffer.putInt(199);
		ByteBuffer new2= ByteBuffer.allocate(32);
		byteBuffer.flip();
		new2.put(byteBuffer);
		// byteBuffer.compact();
		System.out.println(new2.get());
		System.out.println(new2.get(0));
		new2.flip();
		byte[] bytes = new byte[new2.remaining()];
		new2.get(bytes);
	}

	public static void initByteBuffer() {
		byteBuffer = ByteBuffer.allocate(32);
		System.out.println("===============init status============");
		System.out.println("position:" + byteBuffer.position());
		System.out.println("limit:" + byteBuffer.limit());
		System.out.println("capacity:" + byteBuffer.capacity());
	}

}
